#include "headers/Model3d.h"
#include "headers/Utils.h"
#include "GL/glut.h"
#include "headers/Defines.h"
#include "headers/Vector3d.h"
#include <iostream>
#include <cmath>
using namespace std;

class Sweep: public Model3d {
private:
	Vector3d p_start, p_end;
	Vector3d *v;
	int length_of_vertices;
	double scale;
	double extend;

public:
	Sweep(Vector3d start, Vector3d end, Vector3d *v, int len,double scale,double extend) {
		p_start = start;
		p_end = end;
		this->v = v;
		length_of_vertices = len;
		this->scale = scale;
		this->extend = extend;
	}
	void draw() {
		//glutSolidCube(10);
		glPushMatrix();
		{
			//translate
			Vector3d rot_dir = (p_end - p_start).unit();
			Vector3d rot_axis = CROSS(K,rot_dir).unit();
			double rot_angle = acos(DOT(K,rot_dir))*180/PI;
			glRotatef(-rot_angle,rot_axis.x,rot_axis.y,rot_axis.z);
			glTranslatef(p_start.x,p_start.y,p_start.z);

			//draw
			glBegin(GL_QUADS);
			{
				double z = -pointDistance(p_start, p_end);
				for (int i = 0; i < length_of_vertices; i++) {
					Vector3d a = v[i + 1] - v[i];
					Vector3d b = Vector3d(v[i + 1].x, v[i + 1].y, z)
							- Vector3d(v[i].x, v[i].y, 0);
					Vector3d norm = CROSS(a, b).unit();
					glNormal3f(CO(norm));
					glVertex3f(v[i].x * scale, v[i].y * scale, -extend);
					glVertex3f(v[i + 1].x * scale, v[i + 1].y * scale, -extend);
					glVertex3f(v[i + 1].x * scale, v[i + 1].y * scale, z+extend);
					glVertex3f(v[i].x * scale, v[i].y * scale, z+extend);
				}
			}
			glEnd();
		}
		glPopMatrix();

	}
};
